package com.heima.wemedia.feign;

import com.heima.apis.wemedia.IWemediaClient;
import com.heima.common.exception.CustomException;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: WemediaClient
 * Description:
 * date: 2023/8/25 0025 17:50
 *
 * @author zHan
 */
@RestController
@Slf4j
@Api(tags = "自媒体用户相关接口")
public class WemediaClient implements IWemediaClient {

    @Autowired
    private WmUserService wmUserService;

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询自媒体用户
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/api/v1/wemedia/{id}")
    public ResponseResult getWmUser(Integer id) {
        // 参数校验
        if (id == null) {
            throw new CustomException(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return ResponseResult.okResult(wmUserService.getById(id));
    }

    /**
     * 查询所有频道
     *
     * @return
     */
    @Override
    @GetMapping("/api/v1/channel/list")
    public ResponseResult getChannels() {
        return wmChannelService.findAll();
    }
}
